<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="copyBtn">复制文本</button>
    <script>
        const copyBtn = document.querySelector('#copyBtn');
        copyBtn.addEventListener('click', () => {
            const text = 'Hello, World!';
            navigator.clipboard.writeText(text).then(() => {
                console.log('文本复制成功');
            }).catch((err) => {
                console.error('文本复制失败', err);
            });
        });
    </script>
</body>
</html>